<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 表单验证 </title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> 
    <link href="${ctx!}/assets/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx!}/assets/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx!}/assets/css/animate.css" rel="stylesheet">
    <link href="${ctx!}/assets/css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body class="gray-bg">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <form class="form-horizontal m-t" id="frm" method="post" action="${ctx!}/employee/edit">
                        	<input type="hidden" id="id" name="id" value="${employee.id}">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">职工编号：</label>
                                <div class="col-sm-8">
                                    <input id="employeeCode" name="employeeCode" class="form-control" type="text" value="${employee.employeeCode}" <#if employee?exists> readonly="readonly"</#if> >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">职工名字：</label>
                                <div class="col-sm-8">
                                    <input id="employeeName" name="employeeName" class="form-control" type="text" value="${employee.employeeName}"  >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">职工性别：</label>
                                <div class="col-sm-8">
                                	<select name="employeeSex" class="form-control">
                                		<option value="0" <#if employee.employeeSex == 0>selected="selected"</#if>>女</option>
                                		<option value="1" <#if employee.employeeSex == 1>selected="selected"</#if>>男</option>
                                	</select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">电话：</label>
                                <div class="col-sm-8">
                                    <input id="employeePhone" name="employeePhone" class="form-control" value="${employee.employeePhone}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">身份证：</label>
                                <div class="col-sm-8">
                                    <input id="employeeIdcard" name="employeeIdcard" class="form-control" value="${employee.employeeIdcard}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">地址：</label>
                                <div class="col-sm-8">
                                    <input id="address" name="address" class="form-control" value="${employee.address}">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">科室：</label>
                                <div class="col-sm-8">
                                	<select name = 'departmentId' id="selectId" class="form-control">
                                	</select>
                                </div>
                            </div>
                                <div class="col-sm-8 col-sm-offset-3">
                                    <button class="btn btn-primary" type="submit">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>



    <!-- 全局js -->
    <script src="${ctx!}/assets/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctx!}/assets/js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="${ctx!}/assets/js/content.js?v=1.0.0"></script>

    <!--  plugin javascript-->
    <script src="${ctx!}/assets/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${ctx!}/assets/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${ctx!}/assets/js/plugins/layer/layer.min.js"></script>
    <script src="${ctx!}/assets/js/plugins/layer/laydate/laydate.js"></script>
    <script type="text/javascript">
    $(document).ready(function () {
	    $("#frm").validate({
    	    rules: {
                employeeName: {
    	        required: true,
    	        minlength: 3,
    	    	maxlength: 10
    	      },
                employeeCode: {
    	        required: true
    	      },
                employeeSex: {
    	        required: true
    	      },
                employeePhone: {
    	        required: true
    	      },
    	      	address: {
    	        required: true,
    	        maxlength: 40
    	      },
    	      	description: {
    	        required: true,
    	        maxlength: 40
    	      }
    	    },
    	    messages: {},
    	    submitHandler:function(form){
    	    	$.ajax({
   	    		   type: "POST",
   	    		   dataType: "json",
   	    		   url: "${ctx!}/employee/edit",
   	    		   data: $(form).serialize(),
   	    		   success: function(msg){
	   	    			layer.msg(msg.message, {time: 1000},function(){
	   						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	   						parent.layer.close(index); 
	   					});
   	    		   }
   	    		});
            } 
    	});
    });
    </script>

</body>

</html>
<script>
    $(function(){
        initDepartments();
    });
    function initDepartments(){
        $.ajax({
            type: "POST",
            dataType: "json",
            data:{},
            url: "${ctx!}/employee/getAllDepartments",
            success: function(result){
                var departmentList =  result.data;
                if(departmentList){
                    for (var i in  departmentList) {
                       // console.log(departmentList[i].departmentName);
                        $('#selectId').append('<option value='+departmentList[i].id+'>'+departmentList[i].departmentName+'</option>');
                    }
                }
            },
            error:function(){
                alert("发生错误");
            }
        });

    }
</script>